import send_msg from '@feidao-factory/send-msg';
import { ICommonParams } from '../../interfaces';

const IS_ONLINE = 'loginservice.isonline4js.intranet';

/**
 * 用户是否在线
 * @param action_id 系统参数action_id
 * @param session_id 系统参数session_id
 * @param spaceid 系统参数spaceid
 * @param msg 传的参数
 * @example user_isonline(action_id, session_id, msg);
 */
export default async function user_isonline(action_id: string, session_id: string, msg: ICommonParams) {
	const cookie = msg.cookie;
	const sessionid = cookie.sessionid;
	if (sessionid) {
		const param = {
			sessionid
		};
		const data = await send_msg<{ code: 'false' | string; }>(action_id, session_id, IS_ONLINE, param);
		const code = data.code;
		if (code === 'false') {
			return false;
		}
		return true;
	}
	return false;
}
